package com.thread;

/**
 * @author liliang
 * @date 2019/12/19.
 */
public class Test {

    public static void main(String[] args) {
//        new Thread(new PrintTask()).start();
//        new PrintThread().start();
//        Thread thread = new Thread("t1");
//        System.out.println(thread.getPriority());
//        thread.setPriority(Thread.MAX_PRIORITY);
//        System.out.println(thread.getPriority());
//
//        System.out.println("main 线程是否是守护线程:" + Thread.currentThread().isDaemon());
//        Thread t1 = new Thread("t1");
//        System.out.println("t1是否是守护线程:" + t1.isDaemon());
//        t1.setDaemon(true);
//        System.out.println("t1是否是守护线程:" + t1.isDaemon());
//        Thread t1 = new Thread();
//        System.out.println("t1是否是守护线程:" + t1.isDaemon());
//        Thread t2 = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                Thread t3 = new Thread();
//                System.out.println("t3从守护线程中创建的线程是否是守护线程:" + t3.isDaemon());
//            }
//        });
//        t2.setDaemon(true);
//        t2.start();

//        Thread t1 = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i < 5; i++) {
//                    System.out.println(i);
//                    try {
//                        Thread.sleep(1000L);
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//            }
//        },"t1");
//        t1.start();
//
//        Thread t2 = new Thread(new Runnable() {
//            double d = 1.2d;
//            @Override
//            public void run() {
//                try {
//                    t1.join();
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//                System.out.println("线程t1执行完了,该 t2了");
//            }
//        }, "t2");
//        t2.start();
//        Thread thread = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                throw new RuntimeException("t1 异常");
//            }
//        }, "t1");
//
//        thread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
//        thread.start();
        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                throw new RuntimeException("t1 异常");
            }
        }, "t1");
        thread.start();
    }
}
